{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import warnings\n",
    "from functools import reduce\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "%matplotlib inline\n",
    "\n",
    "user_data = pd.read_csv(\"./input/tianchi_fresh_comp_train_user.csv\")\n",
    "item_data = pd.read_csv(\"./input/tianchi_fresh_comp_train_item.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    user_id    item_id  behavior_type user_geohash  item_category  \\\n",
      "0  10001082  285259775              1      97lk14c           4076   \n",
      "1  10001082    4368907              1          NaN           5503   \n",
      "2  10001082    4368907              1          NaN           5503   \n",
      "3  10001082   53616768              1          NaN           9762   \n",
      "4  10001082  151466952              1          NaN           5232   \n",
      "\n",
      "                 time  \n",
      "0 2014-12-08 18:00:00  \n",
      "1 2014-12-12 12:00:00  \n",
      "2 2014-12-12 12:00:00  \n",
      "3 2014-12-02 15:00:00  \n",
      "4 2014-12-12 11:00:00  \n"
     ]
    }
   ],
   "source": [
    "# 转换时间类型\n",
    "user_data[\"time\"] = pd.to_datetime(user_data[\"time\"], format=\"%Y%m%d %H\")\n",
    "print(user_data.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户相关特征提取函数\n",
    "\n",
    "# 用户执行各项type操作的总次数\n",
    "def user_action_total_counts(data):\n",
    "    data[\"user_action_total_counts\"] = 1\n",
    "    feature = data[[\"user_id\", \"user_action_total_counts\"]].groupby([\"user_id\"], as_index=False).count()\n",
    "    return feature\n",
    "# 用户执行type操作的次数  data:数据 type:操作类型 name:新增列名称\n",
    "def user_type_counts(data, type, name):\n",
    "    data[name] = 1\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"user_id\", name]].groupby([\"user_id\"], as_index=False).count()\n",
    "    return feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 商品相关特征提取函数\n",
    "# 商品被执行各项type操作的总次数\n",
    "def item_action_total_counts(data):\n",
    "    data[\"item_action_total_counts\"] = 1\n",
    "    feature = data[[\"item_id\", \"item_action_total_counts\"]].groupby([\"item_id\"], as_index=False).count()\n",
    "    return feature\n",
    "# 对商品执行各项type操作的用户总数\n",
    "def item_total_user_counts(data):\n",
    "    data = data[[\"user_id\", \"item_id\"]].drop_duplicates()\n",
    "    data[\"item_total_user_counts\"] = 1\n",
    "    feature = data[[\"item_id\", \"item_total_user_counts\"]].groupby([\"item_id\"], as_index=False).count()\n",
    "    return feature\n",
    "# 商品被执行type操作的次数\n",
    "def item_type_counts(data, type, name):\n",
    "    data[name] = 1\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"item_id\", name]].groupby([\"item_id\"], as_index=False).count()\n",
    "    return feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 商品类型相关特征提取函数\n",
    "# 此类型商品被执行各项type操作的总次数\n",
    "def category_action_total_counts(data):\n",
    "    data[\"category_action_total_counts\"] = 1\n",
    "    feature = data[[\"item_category\", \"category_action_total_counts\"]].groupby([\"item_category\"], as_index=False).count()\n",
    "    return feature\n",
    "# 对此类型商品执行各项type操作的用户总数\n",
    "def category_total_user_counts(data):\n",
    "    data = data[[\"user_id\", \"item_category\"]].drop_duplicates()\n",
    "    data[\"category_total_user_counts\"] = 1\n",
    "    feature = data[[\"item_category\", \"category_total_user_counts\"]].groupby([\"item_category\"], as_index=False).count()\n",
    "    return feature\n",
    "# 此类型商品被执行type操作的次数\n",
    "def category_type_counts(data, type, name):\n",
    "    data[name] = 1\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"item_category\", name]].groupby([\"item_category\"], as_index=False).count()\n",
    "    return feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户-商品相关特征提取函数\n",
    "# 用户对商品执行各项type操作的总次数\n",
    "def user_item_action_total_counts(data):\n",
    "    data[\"user_item_action_total_counts\"] = 1\n",
    "    feature = data[[\"user_id\", \"item_id\", \"user_item_action_total_counts\"]].groupby([\"user_id\", \"item_id\"], as_index=False).count()\n",
    "    return feature\n",
    "# 用户对商品执行type操作的次数\n",
    "def user_item_type_counts(data, type, name):\n",
    "    data[name] = 1\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"user_id\", \"item_id\", name]].groupby([\"user_id\", \"item_id\"], as_index=False).count()\n",
    "    return feature\n",
    "# 用户对商品执行type操作的最后时间 \n",
    "def user_item_last_type_time(data, type, name):\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"user_id\", \"item_id\", \"time\"]].groupby([\"user_id\", \"item_id\"], as_index=False).max()\n",
    "    feature.rename(columns={\"time\": name}, inplace=True)\n",
    "    return feature\n",
    "\n",
    "# 用户第一次购买特定商品从浏览到购买的时间间隔、过程中的浏览次数和加入购物车到购买的时间间隔\n",
    "def user_item_look_to_buy(data):\n",
    "    # 用户购买过的用户-商品组合\n",
    "    buy_user_item = data[data[\"behavior_type\"] == 4][[\"user_id\", \"item_id\"]].drop_duplicates()\n",
    "    # 用户-商品组合的数据\n",
    "    data = pd.merge(buy_user_item, data, how=\"left\", on=[\"user_id\", \"item_id\"])[[\"user_id\", \"item_id\", \"behavior_type\", \"time\"]]\n",
    "    # 第一次浏览商品的时间\n",
    "    earliest_look = data[data[\"behavior_type\"] == 1].groupby([\"user_id\", \"item_id\"], as_index=False).min()\n",
    "    earliest_look.rename(columns={\"time\": \"earliest_look_time\"}, inplace=True)\n",
    "    # 第一次购买商品的时间\n",
    "    earliest_buy = data[data[\"behavior_type\"] == 4].groupby([\"user_id\", \"item_id\"], as_index=False).min()\n",
    "    earliest_buy.rename(columns={\"time\": \"earliest_buy_time\"}, inplace=True)\n",
    "    # 第一次将商品加入购物车的时间\n",
    "    earliest_add = data[data[\"behavior_type\"] == 3].groupby([\"user_id\", \"item_id\"], as_index=False).min()\n",
    "    earliest_add.rename(columns={\"time\": \"earliest_add_time\"}, inplace=True)\n",
    "    # 第一次购买商品中浏览到购买的时间间隔(单位：小时)\n",
    "    feature = pd.merge(earliest_buy, earliest_look, how=\"left\", on=[\"user_id\", \"item_id\"])\n",
    "    feature[\"earliest_user_item_timedelta_look_to_buy\"] = (feature[\"earliest_buy_time\"] - feature[\"earliest_look_time\"]).dt.total_seconds()/360000\n",
    "    feature = feature[feature[\"earliest_user_item_timedelta_look_to_buy\"] >= 0]\n",
    "    feature = feature[[\"user_id\", \"item_id\", \"earliest_look_time\", \"earliest_buy_time\", \"earliest_user_item_timedelta_look_to_buy\"]]\n",
    "    # 第一次购买商品过程中的浏览次数\n",
    "    data = pd.merge(feature, data, how=\"left\", on=[\"user_id\", \"item_id\"])\n",
    "    data = data[(data[\"behavior_type\"] == 1)&(data[\"time\"] <= data[\"earliest_buy_time\"])]\n",
    "    data[\"item_look_counts_before_buy\"] = 1\n",
    "    item_look_counts_before_buy = data[[\"user_id\", \"item_id\", \"item_look_counts_before_buy\"]].groupby([\"user_id\", \"item_id\"], as_index=False).count()\n",
    "    feature = pd.merge(feature, item_look_counts_before_buy, how=\"left\", on=[\"user_id\", \"item_id\"])\n",
    "    # 返回结果\n",
    "    return feature[[\"user_id\", \"item_id\", \"item_look_counts_before_buy\", \"earliest_user_item_timedelta_look_to_buy\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户-商品类型相关特征提取函数\n",
    "# 用户对同种类型商品执行各项type操作的总次数\n",
    "def user_category_action_total_counts(data):\n",
    "    data[\"user_category_action_total_counts\"] = 1\n",
    "    feature = data[[\"user_id\", \"item_category\", \"user_category_action_total_counts\"]].groupby([\"user_id\", \"item_category\"], as_index=False).count()\n",
    "    return feature\n",
    "# 用户对同种类型商品执行type操作的次数\n",
    "def user_category_type_counts(data, type, name):\n",
    "    data[name] = 1\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"user_id\", \"item_category\", name]].groupby([\"user_id\", \"item_category\"], as_index=False).count()\n",
    "    return feature\n",
    "# 用户对同种类型商品执行type操作的最后时间\n",
    "def user_category_last_type_time(data, type, name):\n",
    "    feature = data[data[\"behavior_type\"] == type][[\"user_id\", \"item_category\", \"time\"]].groupby([\"user_id\", \"item_category\"], as_index=False).max()\n",
    "    feature.rename(columns={\"time\": name}, inplace=True)\n",
    "    return feature\n",
    "# 用户第一次购买同种类型商品从浏览到购买的时间间隔和过程中的浏览次数\n",
    "def user_category_look_to_buy(data):\n",
    "    # 用户购买过的用户-商品类型组合\n",
    "    buy_user_item = data[data[\"behavior_type\"] == 4][[\"user_id\", \"item_category\"]].drop_duplicates()\n",
    "    # 用户-商品类型组合的数据\n",
    "    data = pd.merge(buy_user_item, data, how=\"left\", on=[\"user_id\", \"item_category\"])[[\"user_id\", \"item_category\", \"behavior_type\", \"time\"]]\n",
    "    # 第一次浏览同种类型商品的时间\n",
    "    earliest_look = data[data[\"behavior_type\"] == 1].groupby([\"user_id\", \"item_category\"], as_index=False).min()\n",
    "    earliest_look.rename(columns={\"time\": \"earliest_look_time\"}, inplace=True)\n",
    "    # 第一次购买同种类型商品的时间\n",
    "    earliest_buy = data[data[\"behavior_type\"] == 4].groupby([\"user_id\", \"item_category\"], as_index=False).min()\n",
    "    earliest_buy.rename(columns={\"time\": \"earliest_buy_time\"}, inplace=True)\n",
    "    # 第一次将同种类型商品加入购物车的时间\n",
    "    earliest_add = data[data[\"behavior_type\"] == 3].groupby([\"user_id\", \"item_category\"], as_index=False).min()\n",
    "    earliest_add.rename(columns={\"time\": \"earliest_add_time\"}, inplace=True)\n",
    "    # 第一次购买同种类型商品中浏览到购买的时间间隔(单位：小时)\n",
    "    feature = pd.merge(earliest_buy, earliest_look, how=\"left\", on=[\"user_id\", \"item_category\"])\n",
    "    feature[\"earliest_user_category_timedelta_look_to_buy\"] = (feature[\"earliest_buy_time\"] - feature[\"earliest_look_time\"]).dt.total_seconds()/3600\n",
    "    feature = feature[feature[\"earliest_user_category_timedelta_look_to_buy\"] >= 0]\n",
    "    feature = feature[[\"user_id\", \"item_category\", \"earliest_look_time\", \"earliest_buy_time\", \"earliest_user_category_timedelta_look_to_buy\"]]\n",
    "    # 第一次购买同种类型商品过程中的浏览次数\n",
    "    data = pd.merge(feature, data, how=\"left\", on=[\"user_id\", \"item_category\"])\n",
    "    data = data[(data[\"behavior_type\"] == 1)&(data[\"time\"] <= data[\"earliest_buy_time\"])]\n",
    "    data[\"category_look_counts_before_buy\"] = 1\n",
    "    category_look_counts_before_buy = data[[\"user_id\", \"item_category\", \"category_look_counts_before_buy\"]].groupby([\"user_id\", \"item_category\"], as_index=False).count()\n",
    "    feature = pd.merge(feature, category_look_counts_before_buy, how=\"left\", on=[\"user_id\", \"item_category\"])\n",
    "    # 返回结果\n",
    "    return feature[[\"user_id\", \"item_category\", \"category_look_counts_before_buy\", \"earliest_user_category_timedelta_look_to_buy\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge_user(data1, data2):\n",
    "    data = pd.merge(data1, data2, how=\"left\", on=\"user_id\")\n",
    "    return data\n",
    "def merge_item(data1, data2):\n",
    "    data = pd.merge(data1, data2, how=\"left\", on=\"item_id\")\n",
    "    return data\n",
    "def merge_category(data1, data2):\n",
    "    data = pd.merge(data1, data2, how=\"left\", on=\"item_category\")\n",
    "    return data\n",
    "def merge_user_item(data1, data2):\n",
    "    data = pd.merge(data1, data2, how=\"left\", on=[\"user_id\", \"item_id\"])\n",
    "    return data\n",
    "def merge_user_category(data1, data2):\n",
    "    data = pd.merge(data1, data2, how=\"left\", on=[\"user_id\", \"item_category\"])\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造特征函数 predict_date:预测日期\n",
    "def get_feature(predict_date):\n",
    "    train_data = user_data[user_data[\"time\"] < predict_date]\n",
    "#     # 用户相关特征\n",
    "#     # u1:用户执行各项type操作的总次数\n",
    "#     u1 = user_action_total_counts(train_data)\n",
    "#     # u2:用户浏览商品的次数\n",
    "#     u2 = user_type_counts(train_data, 1, \"user_look_counts\")\n",
    "#     # u3:用户收藏商品的次数\n",
    "#     u3 = user_type_counts(train_data, 2, \"user_like_counts\")\n",
    "#     # u4:用户加入购物车的次数\n",
    "#     u4 = user_type_counts(train_data, 3, \"user_add_counts\")\n",
    "#     # u5:用户购买商品的次数\n",
    "#     u5 = user_type_counts(train_data, 4, \"user_buy_counts\")\n",
    "    \n",
    "#     # 商品相关特征\n",
    "#     # i1:商品被执行各项type操作的总次数\n",
    "#     i1 = item_action_total_counts(train_data)\n",
    "#     # i2:对商品执行各项type操作的用户总数\n",
    "#     i2 = item_total_user_counts(train_data)\n",
    "#     # i3:商品被浏览的次数\n",
    "#     i3 = item_type_counts(train_data, 1, \"item_look_counts\")\n",
    "#     # i4:商品被收藏的次数\n",
    "#     i4 = item_type_counts(train_data, 2, \"item_like_counts\")\n",
    "#     # i5:商品被加入购物车的次数\n",
    "#     i5 = item_type_counts(train_data, 3, \"item_add_counts\")\n",
    "#     # i6:商品被购买的次数\n",
    "#     i6 = item_type_counts(train_data, 4, \"item_buy_counts\")\n",
    "    \n",
    "#     # 商品类型特征\n",
    "#     # c1:商品被执行各项type操作的总次数\n",
    "#     c1 = category_action_total_counts(train_data)\n",
    "#     # c2:对商品执行各项type操作的用户总数\n",
    "#     c2 = category_total_user_counts(train_data)\n",
    "#     # c3:此类型商品被浏览的次数\n",
    "#     c3 = category_type_counts(train_data, 1, \"category_look_counts\")\n",
    "#     # c4:此类型商品被收藏的次数\n",
    "#     c4 = category_type_counts(train_data, 2, \"category_like_counts\")\n",
    "#     # c5:此类型商品被加入购物车的次数\n",
    "#     c5 = category_type_counts(train_data, 3, \"category_add_counts\")\n",
    "#     # c6:此类型商品被购买的次数\n",
    "#     c6 = category_type_counts(train_data, 4, \"category_buy_counts\")\n",
    "    \n",
    "    # 用户-商品相关特征\n",
    "    # ui1:用户对商品执行各项type操作的总次数\n",
    "#     ui1 = user_item_action_total_counts(train_data)\n",
    "    # ui2:用户浏览特定商品的次数\n",
    "    ui2 = user_item_type_counts(train_data, 1, \"user_item_look_counts\")\n",
    "#     # ui3:用户收藏特定商品的次数\n",
    "#     ui3 = user_item_type_counts(train_data, 2, \"user_item_like_counts\")\n",
    "#     # ui4:用户将特定商品加入购物车的次数\n",
    "#     ui4 = user_item_type_counts(train_data, 3, \"user_item_add_counts\")\n",
    "    # ui5:用户购买特定商品的次数\n",
    "    ui5 = user_item_type_counts(train_data, 4, \"user_item_buy_counts\")\n",
    "    # ui6:用户浏览特定商品的最后时间\n",
    "    ui6 = user_item_last_type_time(train_data, 1, \"user_item_last_look_time\")\n",
    "    # ui7:用户收藏特定商品的最后时间\n",
    "    ui7 = user_item_last_type_time(train_data, 2, \"user_item_last_like_time\")\n",
    "    # ui8:用户将特定商品加入购物车的最后时间\n",
    "    ui8 = user_item_last_type_time(train_data, 3, \"user_item_last_add_time\")\n",
    "    # ui9:用户购买特定商品的最后时间\n",
    "    ui9 = user_item_last_type_time(train_data, 4, \"user_item_last_buy_time\")\n",
    "    # ui10:用户第一次购买特定商品从浏览到购买的时间间隔和过程中的浏览次数\n",
    "    ui10 = user_item_look_to_buy(train_data)\n",
    "    \n",
    "    # 用户-商品类型相关特征\n",
    "    # uc1:用户对同种类型商品执行各项type操作的总次数\n",
    "#     uc1 = user_category_action_total_counts(train_data)\n",
    "#     # uc2:用户浏览同种类型商品的次数\n",
    "    uc2 = user_category_type_counts(train_data, 1, \"user_category_look_counts\")\n",
    "#     # uc3:用户收藏同种类型商品的次数\n",
    "#     uc3 = user_category_type_counts(train_data, 2, \"user_category_like_counts\")\n",
    "#     # uc4:用户将同种类型商品加入购物车的次数\n",
    "#     uc4 = user_category_type_counts(train_data, 3, \"user_category_add_counts\")\n",
    "    # uc5:用户购买同种类型商品的次数\n",
    "    uc5 = user_category_type_counts(train_data, 4, \"user_category_buy_counts\")\n",
    "    # uc6:用户浏览同种类型商品的最后时间\n",
    "    uc6 = user_category_last_type_time(train_data, 1, \"user_category_last_look_time\")\n",
    "    # uc7:用户收藏同种类型商品的最后时间\n",
    "    uc7 = user_category_last_type_time(train_data, 2, \"user_category_last_like_time\")\n",
    "    # uc8:用户将同种类型商品加入购物车的最后时间\n",
    "    uc8 = user_category_last_type_time(train_data, 3, \"user_category_last_add_time\")\n",
    "    # uc9:用户购买同种类型商品的最后时间\n",
    "    uc9 = user_category_last_type_time(train_data, 4, \"user_category_last_buy_time\")\n",
    "    # uc10:用户第一次购买同种类型商品从浏览到购买的时间间隔和过程中的浏览次数\n",
    "    uc10 = user_category_look_to_buy(train_data)\n",
    "    \n",
    "    # 联结表\n",
    "    train_data = train_data[[\"user_id\", \"item_id\", \"item_category\"]].drop_duplicates()\n",
    "#     train_data = reduce(merge_user, [train_data, u1, u2, u3, u4, u5])\n",
    "#     train_data = reduce(merge_item, [train_data, i1, i2, i3, i4, i5, i6])\n",
    "#     train_data = reduce(merge_category, [train_data, c1, c2, c3, c4, c5, c6])\n",
    "#     train_data = reduce(merge_user_item, [train_data, ui1, ui2, ui3, ui4, ui5, ui6, ui7, ui8, ui9, ui10])\n",
    "#     train_data = reduce(merge_user_category, [train_data, uc1, uc2, uc3, uc4, uc5, uc6, uc7, uc8, uc9, uc10])\n",
    "    train_data = reduce(merge_user_item, [train_data, ui2, ui5, ui6, ui7, ui8, ui9, ui10])#reduce(函数+[1,2,3])\n",
    "    train_data = reduce(merge_user_category, [train_data, uc2, uc5, uc6, uc7, uc8, uc9, uc10])\n",
    "    # 距预测日期的时间间隔 单位：小时\n",
    "    train_data[\"user_item_last_look_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_item_last_look_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_item_last_like_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_item_last_like_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_item_last_add_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_item_last_add_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_item_last_buy_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_item_last_buy_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_category_last_look_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_category_last_look_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_category_last_like_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_category_last_like_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_category_last_add_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_category_last_add_time\"]).dt.total_seconds()/3600\n",
    "    train_data[\"user_category_last_buy_to_now\"] = (pd.to_datetime(predict_date) - train_data[\"user_category_last_buy_time\"]).dt.total_seconds()/3600\n",
    "    # 删除无用特征\n",
    "    drop_columns = [\"user_item_last_look_time\", \"user_item_last_like_time\", \"user_item_last_add_time\", \"user_item_last_buy_time\"]\n",
    "    drop_columns += [\"user_category_last_look_time\", \"user_category_last_like_time\", \"user_category_last_add_time\", \"user_category_last_buy_time\"]\n",
    "    train_data = train_data.drop(drop_columns, axis=1)\n",
    "    # 处理缺失值\n",
    "#     fill_columns = [\"user_look_counts\", \"user_like_counts\", \"user_add_counts\", \"user_buy_counts\"]\n",
    "#     fill_columns += [\"item_look_counts\", \"item_like_counts\", \"item_add_counts\", \"item_buy_counts\"]\n",
    "#     fill_columns += [\"category_look_counts\", \"category_like_counts\", \"category_add_counts\", \"category_buy_counts\"]\n",
    "    fill_columns = [\"user_item_look_counts\", \"user_item_buy_counts\"]\n",
    "    fill_columns += [\"user_category_look_counts\", \"user_category_buy_counts\"]\n",
    "    train_data[fill_columns] = train_data[fill_columns].fillna(0)\n",
    "    return train_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_train = get_feature(\"2014-12-17\")\n",
    "data_eval = get_feature(\"2014-12-18\")\n",
    "data_test = get_feature(\"2014-12-19\")\n",
    "data_train.to_csv(\"./data_result/data_train.csv\", index=False)\n",
    "data_eval.to_csv(\"./data_result/data_eval.csv\", index=False)\n",
    "data_test.to_csv(\"./data_result/data_test.csv\", index=False)\n",
    "user_data.to_csv(\"./data_result/user_data.csv\", index=False)\n",
    "item_data.to_csv(\"./data_result/item_data.csv\", index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
